package com.easyUploader.assembler;

import com.common.mybaits.CustomPage;
import com.easyUploader.entity.dao.Bucket;
import com.easyUploader.entity.dto.BucketDto;
import com.easyUploader.entity.dto.FileDto;
import com.easyUploader.entity.pojo.BucketStatus;
import com.easyUploader.property.LocalFileProperty;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

import static com.easyUploader.entity.factory.BucketFactory.BUCKET_CONVERTER;
import static com.easyUploader.entity.pojo.BucketStatus.NO_SYSTEM_RESOURCE;
import static com.easyUploader.entity.pojo.BucketStatus.SYSTEM_RESOURCE;

/**
 * @author 大忽悠
 * @create 2022/11/1 14:12
 */
@RequiredArgsConstructor
@Component
public class BucketAssembler {
    private final LocalFileProperty localFileProperty;

    public List<BucketDto> assembler(List<Bucket> bucketList){
        List<BucketDto> bucketDtos = BUCKET_CONVERTER.toListBucketDto(bucketList);
        bucketDtos.forEach(bucketDto->bucketDto.buildFileInfo(localFileProperty));
        return bucketDtos;
    }

    public BucketDto getShareBucket() {
        BucketDto bucketDto = BucketDto.builder().name(LocalFileProperty.DEFAULT_BUCKET)
                .bucketType(BucketStatus.BUCKET_STATUS_READ_ONLY)
                .accessType(BucketStatus.ACCESS_STATUS_PUBLIC)
                .system(SYSTEM_RESOURCE)
                .path(LocalFileProperty.DEFAULT_BUCKET).build();
        bucketDto.buildShareFileInfo(localFileProperty);
        return bucketDto;
    }

    public List<FileDto> listShareFiles(String dir, CustomPage customPage) {
        BucketDto shareBucket = getShareBucket();
        return shareBucket.listShareFiles(dir,customPage,localFileProperty);
    }
}
